//
//  UIScrollView+RNOLRefresh.m
//  RongNiuOnline
//
//  Created by apple on 2018/5/6.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "UIScrollView+RNOLRefresh.h"

@implementation UIScrollView (RNOLRefresh)

//MARK:-添加下拉刷新
-(void)addHeaderRefreshWithTarget:(id)target  eventAction:(SEL)action{
    //下拉刷新
    MJRefreshNormalHeader * header =
    [MJRefreshNormalHeader headerWithRefreshingTarget: target refreshingAction: action];
    // 设置文字
    [header setTitle:@"下拉刷新提供最新数据" forState:MJRefreshStateIdle];
    [header setTitle:@"松开即可刷新最新数据" forState:MJRefreshStatePulling];
    [header setTitle:@"正在加载最新数据..." forState:MJRefreshStateRefreshing];
    // 设置字体
    header.stateLabel.font = KFontSize(15);
    header.stateLabel.textColor = kAppMainColor;
    header.lastUpdatedTimeLabel.font = KFontSize(12);
    header.lastUpdatedTimeLabel.textColor = kAppMainColor;
    header.automaticallyChangeAlpha = YES;
    self.mj_header = header;
}

//MARK:-添加上拉加载
-(void)addFooterRefreshWithTarget:(id)target  eventAction:(SEL)action{
    MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:target refreshingAction: action];
    // 设置文字
    [footer setTitle:@"上拉加载更多数据" forState:MJRefreshStateIdle];
    [footer setTitle:@"正在加载数据..." forState:MJRefreshStateRefreshing];
    [footer setTitle:@"没有更多数据了" forState:MJRefreshStateNoMoreData];

    footer.stateLabel.font = KFontSize(15);
    footer.automaticallyHidden = YES ;
    footer.stateLabel.textColor = kAppMainColor ;
    self.mj_footer = footer;
}


//MARK:-开始刷新
- (void)beginRefreshing{
    [self.mj_header beginRefreshing];
}
//MARK:-设置没有更多数据可以加载的状态
- (void)setFooterNoMoreDataState{
    [self.mj_footer setState: MJRefreshStateNoMoreData];
}

//MARK:- 释放刷新
- (void)releaseRefresh{
    if ([self.mj_header isRefreshing]) {
        [self.mj_header endRefreshing];
    }
    if ([self.mj_footer isRefreshing]) {
        [self.mj_footer endRefreshing];
    }
}




@end
